﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wwtfly.BBS.BackBLL.Plays;
using System.Data;
using Wwtfly.Utility;
using Wwtfly.BBS.Framework;
using Wwtfly.BBS.Framework.Caches;
namespace Wwtfly.BBS.ForeApplication.WebForm
{
    public partial class LotteryListShows : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridViewBind();
        }
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridHeader));
            }

            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridHeader));
            }
        }

        protected void DrawGridHeader(HtmlTextWriter output, Control ctl)
        {
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#e8f1f8'>期号</td>");
            output.Write("<td rowspan='3' align='center' valign='middle' bgcolor='#e8f1f8'>红 球 号 码</td>");
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#e8f1f8'>蓝球号码</td>");
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#e8f1f8'>红球和值</td>");
            output.Write("<td rowspan='2' colspan='7'　align='center' valign='middle' bgcolor='#e8f1f8'>红球大码个数（大码为：17-33）</td>");
            output.Write("<td rowspan='2' colspan='2'　align='center' valign='middle' bgcolor='#e8f1f8'>蓝球</td>");
            output.Write("<td colspan='12'　align='center' valign='middle' bgcolor='#e8f1f8' height='18'>红球按从小到大顺序排列</td>");
            output.Write("<td rowspan='2' colspan='2'　align='center' valign='middle' bgcolor='#e8f1f8'>红和尾数</td>");
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#e8f1f8'>大小比</td>");

            output.Write("<tr align='center' valign='middle' bgcolor='#e8f1f8'>");
            output.Write("<td colspan='2'>红1</td>");
            output.Write("<td colspan='2'>红2</td>");
            output.Write("<td colspan='2'>红3</td>");
            output.Write("<td colspan='2'>红4</td>");
            output.Write("<td colspan='2'>红5</td>");
            output.Write("<td colspan='2'>红6</td>");

            output.Write("<tr align='center' valign='middle' bgcolor='#e8f1f8'>");

            for (int i = 0; i < 7; i++)
            {
                output.Write("<td bgcolor='#e8f1f8'>");
                output.Write(i.ToString() + "</td>");
            }

            for (int i = 0; i < 8; i++)
            {
                output.Write("<td bgcolor='#e8f1f8' align='center' valign='middle' height='18'>小</td>");
                output.Write("<td bgcolor='#e8f1f8' align='center' valign='middle'>大</td>");
            }
        }
        protected void GridViewBind()
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(30, "", ""); //，默认显示30期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息！;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        public DataTable SSQ_DX_Select(int num, string str1, string str2)
        {
            DataTable dt = null;
            DataTable dt1 = null;

            dt = CacheHelper.Get("SSQ_DX_Select") as DataTable;

            if (dt == null || dt.Rows.Count < 1)
            {
                dt = PlaysBLL.SelectSSQdxListWinber();
                CacheHelper.Insert("SSQ_DX_Select", dt);
            }

            dt1 = dt.Clone();

            //通过期号来查询
            if (num == 0)
            {
                int i = str1.AsInt(0); 
                int j = str2.AsInt(0);

                DataRow[] dr2 = dt.Select("Isuse>=" + i + " and  Isuse<=" + j);

                foreach (DataRow r in dr2)
                {
                    dt1.Rows.Add(r.ItemArray);
                }
            }

            //通过按纽选择查询多少期
            else
            {
                if (num >= dt.Rows.Count)
                {
                    num = dt.Rows.Count;
                }

                int ii = dt.Rows.Count;                           //总记录数
                int jj = ii - num;

                DataRow[] drr = dt.Select("id > " + jj + " and id <= " + ii);

                foreach (DataRow rr in drr)
                {
                    dt1.Rows.Add(rr.ItemArray);
                }
            }

            return dt1;
        }
        //搜索
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (tb1.Text == "" || tb1.Text == null || tb2.Text == "" || tb2.Text == null)
            {
                Response.Write("<script> alert('请输入起止期数！');</script>");
            }

            int i = tb1.Text.AsInt(0);
            int j = tb2.Text.AsInt(0);
            if (i > j)
            {
                Response.Write("<script> alert('起始期数输入有误，请查证在输入！');</script>");
                return;
            }

            DataTable dt = null;

            dt =SSQ_DX_Select(0, tb1.Text.ToString(), tb2.Text.ToString());

            if (dt == null || dt.Rows.Count < 1)
            {
                Response.Write("<script> alert('数据库里没有此彩种开奖号码信息！');</script>");
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示30
        protected void Button2_Click(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(30, "", ""); //，默认显示30期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示50
        protected void Button3_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(50, "", ""); //，默认显示50期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示100
        protected void Button4_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(100, "", ""); //，默认显示100期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        protected void ColorBind()
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                for (int j = 11; j < 25; j++)
                {
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(0) < 10 &&GridView1.Rows[i].Cells[j].Text.AsInt(0) != 0)
                    {
                        GridView1.Rows[i].Cells[j].Text = "0" + GridView1.Rows[i].Cells[j].Text;
                    }
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(0) == 0)
                    {
                        GridView1.Rows[i].Cells[j].Text = "&nbsp;";
                    }
                }

                for (int j = 4; j < 11; j++)
                {
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(-1) == -1)
                    {
                        GridView1.Rows[i].Cells[j].Text = "&nbsp;";
                    }
                }

                for (int j = 25; j < 27; j++)
                {
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(0) == 0)
                    {
                        GridView1.Rows[i].Cells[j].Text = "&nbsp;";
                    }
                }
            }
        }
    }
}